

import requests

import json

import time

from .casesuit.get_redis import  *
from .conf.config import  *
from .comm.random_number import  Randoms
from .comm.check import Check
from .comm.backend_login import  LoginBackend
from .casesuit.test_register_code import  RegisterCode
from . import web
from flask import request, flash, url_for, render_template
from flask import Response
from app.web.comm.encry import  *
C=Check()
LB=LoginBackend()
requests.packages.urllib3.disable_warnings()  # Python的第三方库requests提示警告InsecureRequestWarning的问题
username = "1811108@gaopeng.com"#服务商
channel="GP518001"
@web.route("/register")
def register_index():
    pass
    return render_template('register.html')

@web.route('/cloud/register',methods=['GET', 'POST'])
def register():#注册商户
    if request.method=="POST":
        # channel=request.get_json()
        channel=request.values.get("merchant_channel")
        # provider_id = C.coonect_db(database='fpmerchant', sql="select id from m_service_provider where username='%s'" %username)[0]
        provider_id=605
        # print("服务商id",channel,channel1 )
        url=base_url_cloud +"/v3/client/register?sid=&token="
        data={
            "name":"接口注册测试",
            "tax_code":"778888822222222",
            "mobile":"15667777777",
            "mobile_code":"1111",
            "password":"zxz123456",
            "legal_person_name":"测试",
            "register_code":""
        }
        tax_code=Randoms().tax_code()
        data["tax_code"]=AES_Encrypt(data=tax_code)#获取随机税号
        mobile=Randoms().telephone()
        data["mobile"]=AES_Encrypt(data=mobile)#获取随机手机号
        Get_redis().get_sms(data["mobile"])
        print("已点击获取验证码按钮")
        data["mobile_code"]=Get_redis().get_mobile_code(phone=mobile)
        data['registration_code']=RegisterCode().test_register_code(channel,provider_id)#根据渠道生成注册码
        print("获取到的注册码：", data['registration_code'])
        # data['registration_code']="02TO8N"
        print("生成注册码成功")


        print(data["mobile_code"])
        print("提交注册请求数据：%s"%data)
        response = requests.post( url=url, json=data, verify=False)
        print(response.json())
        a = response.text
        try:
            register_status= C.coonect_db(database='fpmerchant', sql="select register_status from m_sell_client_new where tax_code='%s'" % tax_code)[0][0]
            print(type(register_status))
            if register_status == 1:
                print('已经审核')
            elif register_status == 0:
                LB.test_cerficate_merchant(tax_code, username)
                print("现在审核")
            else:
                print("商户注册异常")
            print('商户平台注册接口：%s' % a)
        except Exception as e:
            print(e)
            print("数据库没有找到该商户！！")
        # return ("税号：%s注册成功 "%data["tax_code"])
        return render_template("register.html",cont="云平台注册税号："+tax_code)

    else:
        return("注册失败")
    # return render_template('index.html')#,{"RepeatMessage": "注册成功"}
    # return Response("注册成功")

